package org.boulderfoodrescue.webapp.shared;

import java.io.Serializable;

public class Pickup implements Serializable{
	private static final long serialVersionUID = -2242341971007037433L;
	/* Pickup Information */
	private Long databaseKey;

	/* Keys used for database lookup */
	private Long donorKey;
	private Long recipientKey;
	private Long volunteerKey;
	private Long oneTimeEventPickupKey;
	private Long recurringEventPickupKey;
	private Long oneTimeEventDropOffKey;
	private Long recurringEventDropOffKey;

	/* Realted Classes */
	private UserAccountDetails volunteer;
	private Location donor;
	private Location recipient;

	private Boolean recurring;
	private OneTimeEvent oneTimeEventPickup;
	private RecurringEvent recurringEventPickup;
	private OneTimeEvent oneTimeEventDropOff;
	private RecurringEvent recurringEventDropOff;

	private TransportationType transType;
	private String notes;
	public Long getDatabaseKey() {
		return databaseKey;
	}
	public void setDatabaseKey(Long databaseKey) {
		this.databaseKey = databaseKey;
	}
	public Long getDonorKey() {
		return donorKey;
	}
	public void setDonorKey(Long donorKey) {
		this.donorKey = donorKey;
	}
	public Long getRecipientKey() {
		return recipientKey;
	}
	public void setRecipientKey(Long recipientKey) {
		this.recipientKey = recipientKey;
	}
	public Long getVolunteerKey() {
		return volunteerKey;
	}
	public void setVolunteerKey(Long volunteerKey) {
		this.volunteerKey = volunteerKey;
	}
	public Long getOneTimeEventPickupKey() {
		return oneTimeEventPickupKey;
	}
	public void setOneTimeEventPickupKey(Long oneTimeEventPickupKey) {
		this.oneTimeEventPickupKey = oneTimeEventPickupKey;
	}
	public Long getRecurringEventPickupKey() {
		return recurringEventPickupKey;
	}
	public void setRecurringEventPickupKey(Long recurringEventPickupKey) {
		this.recurringEventPickupKey = recurringEventPickupKey;
	}
	public Long getOneTimeEventDropOffKey() {
		return oneTimeEventDropOffKey;
	}
	public void setOneTimeEventDropOffKey(Long oneTimeEventDropOffKey) {
		this.oneTimeEventDropOffKey = oneTimeEventDropOffKey;
	}
	public Long getRecurringEventDropOffKey() {
		return recurringEventDropOffKey;
	}
	public void setRecurringEventDropOffKey(Long recurringEventDropOffKey) {
		this.recurringEventDropOffKey = recurringEventDropOffKey;
	}
	public UserAccountDetails getVolunteer() {
		return volunteer;
	}
	public void setVolunteer(UserAccountDetails volunteer) {
		this.volunteer = volunteer;
		if(volunteer != null)
			this.volunteerKey = volunteer.getDatabaseKey();
		else
			volunteerKey = null;
	}
	public Location getDonor() {
		return donor;
	}
	public void setDonor(Location donor) {
		this.donor = donor;
		this.donorKey = donor.getDatabaseKey();
	}
	public Location getRecipient() {
		return recipient;
	}
	public void setRecipient(Location recipient) {
		this.recipient = recipient;
		if(recipient != null)
			this.recipientKey = recipient.getDatabaseKey();
		else
			recipientKey = null;
	}
	public Boolean getRecurring() {
		return recurring;
	}
	public void setRecurring(Boolean recurring) {
		this.recurring = recurring;
	}
	public OneTimeEvent getOneTimeEventPickup() {
		return oneTimeEventPickup;
	}
	public void setOneTimeEventPickup(OneTimeEvent oneTimeEventPickup) {
		this.oneTimeEventPickup = oneTimeEventPickup;
		if(oneTimeEventPickup != null)
			this.oneTimeEventPickupKey = oneTimeEventPickup.getDatabaseKey();
		else
			this.oneTimeEventPickupKey = null;
	}
	public RecurringEvent getRecurringEventPickup() {
		return recurringEventPickup;
	}
	public void setRecurringEventPickup(RecurringEvent recurringEventPickup) {
		this.recurringEventPickup = recurringEventPickup;
		if(recurringEventPickup != null)
			this.recurringEventPickupKey = recurringEventPickup.getDatabaseKey();
		else
			this.recurringEventPickupKey = null;
	}
	public OneTimeEvent getOneTimeEventDropOff() {
		return oneTimeEventDropOff;
	}
	public void setOneTimeEventDropOff(OneTimeEvent oneTimeEventDropOff) {
		this.oneTimeEventDropOff = oneTimeEventDropOff;
		if(oneTimeEventDropOff != null)
			this.oneTimeEventDropOffKey = oneTimeEventDropOff.getDatabaseKey();
		else
			this.oneTimeEventDropOffKey = null;
	}
	public RecurringEvent getRecurringEventDropOff() {
		return recurringEventDropOff;
	}
	public void setRecurringEventDropOff(RecurringEvent recurringEventDropOff) {
		this.recurringEventDropOff = recurringEventDropOff;
		if(recurringEventDropOff != null)
			this.recurringEventDropOffKey = recurringEventDropOff.getDatabaseKey();
		else
			this.recurringEventDropOffKey = null;
	}
	public TransportationType getTransportationType() {
		return transType;
	}
	public void setTransportationType(TransportationType transType) {
		this.transType = transType;
	}
	public Long getTransportationAsLong() {
		switch(transType)
		{
		case Bike: return 0l;
		case Car: return 1l;
		case Walking: return 2l;
		case Other: return 3l;
		}
		return 0l;
	}

	public void setTransportationViaLong(Long transportation) {
		switch(transportation.intValue())
		{
		case 0: this.transType = TransportationType.Bike;break;
		case 1: this.transType = TransportationType.Car;break;
		case 2: this.transType = TransportationType.Walking; break;
		case 3: this.transType = TransportationType.Other; break;
		}
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public String getDiscription() {
		StringBuilder sb = new StringBuilder();
		sb.append(donor.getName());
		sb.append(" ");
		if(oneTimeEventPickup != null)
			sb.append(oneTimeEventPickup.getEventSummary());
		else
			sb.append(recurringEventPickup.getEventSummary());
		return sb.toString();
	}
}
